//https://leetcode.cn/problems/multiply-strings/description/
class Solution {
public:
    string multiply(string num1, string num2) {
        if (num1 == "0" || num2 == "0") return "0";

        int len1 = num1.size(), len2 = num2.size();
        string result(len1 + len2, '0');

        for (int i = len1 - 1; i >= 0; --i) {
            for (int j = len2 - 1; j >= 0; --j) {
                int mul = (num1[i] - '0') * (num2[j] - '0');
                int sum = mul + (result[i + j + 1] - '0');
                result[i + j + 1] = (sum % 10) + '0';
                result[i + j] += sum / 10;
            }
        }
        size_t start = result.find_first_not_of('0');
        return start == string::npos ? "0" : result.substr(start);
    }
};